﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace AUV5.DAL.Handler
{
    public class ContactListHandler
    {
        public IList<Model.ContactList> contactlist = new List<Model.ContactList>();
        public void GetFullList(object sender, object parameterObj, IList list)
        {
            Model.ContactList orderinfo = GetFullOrder(sender);
            if (orderinfo != null)
            {
                contactlist.Add(orderinfo);
            }
        }
        private Model.ContactList GetFullOrder(object sender)
        {
            try
            {
                if (sender != null)
                {
                    Model.ContactList contact = (Model.ContactList)sender;
                    Model.UserInfo user = new Model.UserInfo();

                    //ContactUserName
                    user.UserID = contact.ContactUserID;
                    Model.UserInfo contactuser = new Model.UserInfo();
                    contactuser = Dao.UserInfoSqlMapDao.Instance.GetDetail(user);
                    if (contactuser != null)
                    {
                        contact.ContactUserName = contactuser.UserName;
                    }
                    else
                    {
                        contact.ContactUserName = "找不到联系人";
                    }

                    //FirstMessage

                    Model.Message firstrecord = Dao.MessageSqlMapDao.Instance.GetDetail(contact.FirstMessage);
                    if (firstrecord != null)
                    {
                        contact.FirstRecord = firstrecord;
                    }

                    //LatestMessage
                    Model.Message latestrecord = Dao.MessageSqlMapDao.Instance.GetDetail(contact.LatestMessage);
                    if (latestrecord != null)
                    {
                        contact.LatestRecord = latestrecord;
                    }


                    return contact;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error executing ContactListHandler,  Cause: " + e.Message, e);
            }
        }
    }
}
